package com.bwie.service.impl;

import com.bwie.common.domain.Home;
import com.bwie.mapper.HomeMapper;
import com.bwie.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: HomeServiceImpl
 * @Description: TODO
 * @version: v1.８.0
 * @author: 李明
 * @date: 2025/10/22 13:04
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private HomeMapper homeMapper;


    @Override
    public List<Home> homeList(Integer userId) {
        List<Home> homeList = homeMapper.homeList(userId);
        List<Home> note = getNote(homeList, 0);
        return note;
    }

    private List<Home> getNote(List<Home> homeList, Integer pid) {
        ArrayList<Home> homes = new ArrayList<>();
        for (Home home : homeList) {
            if (home.getPid().equals(pid)){
                List<Home> note = getNote(homeList, home.getId());
                home.setChildren(note);
                homes.add(home);
            }
        }
        return homes;
    }
}
